<?php
/**
 * 首页接口<搜索列表，搜索详情，生成订单，乘机人>
 * Created by PhpStorm.
 * User: Earl <guo@seosite.cn>
 * Date: 2017/9/11
 * Time: 下午3:04
 * Updatetime:
 * updater：
 */

namespace Wap\Controller;

use lyf\Tree;

class HomeController extends BaseController
{

    /**
     * @desc 直播用户权限：0 所有人可见，1 粉丝，2会员或付费，3仅付费，4凭借密码，5 F码（用户输入个人的ID）
     * @param $k
     */
    private function direct_auth($k)
    {
        $list[0] = '所有人可见';
        $list[1] = '粉丝';
        $list[2] = '会员或付费';
        $list[3] = '仅付费';
        $list[4] = '凭借密码';
        $list[5] = 'F码';
        return $list[$k];
    }

    /**
     * @desc 直播会议方式：1 线上，2线下，3线上+线下
     */
    private function direct_meeting_type($k)
    {
        $list[1] = '线上';
        $list[2] = '线下';
        $list[3] = '线上+线下';
        return $list[$k];
    }

    /**
     * @desc 直播状态：0 待审核，1 正常（默认），2 禁用 ，3 初始化（也不显示）
     */
    private function statusToText($k)
    {
        $list[0] = '待审核';
        $list[1] = '正常';
        $list[2] = '禁用';
        $list[3] = '初始化';
        return $list[$k];
    }

    /**
     * @desc  直播间状态：0未直播，1直播中，2直播录制
     * @author Egor<http://gitee.com/seosite>
     * @param $k
     * @return mixed
     */
    private function directStatusToText($k)
    {
        $list[0] = '未直播';
        $list[1] = '直播中';
        $list[2] = '直播录制';
        return $list[$k];
    }

    /**
     * @desc 用户权限：0 所有人可见，1 粉丝，2会员或付费，3仅付费，4凭借密码，5 F码（用户输入个人的ID）
     * @param $auth
     */
    private function _u_auth_($param,$type)
    {
        if (empty($this->userInfo)) return showErrorMsg(L('_TOKEN_USELESS_'),100004);

        $id = $param['id'];
        switch ($type){
            case 1://视频
                $model = M('video');
                $workInfo = $model->find($id);
                break;
            case 2://直播
                $model = M('direct');
                $workInfo = $model->find($id);
                if ($workInfo['end_time']<time()) return showErrorMsg('喵喵喵~该直播已经结束啦~~~~',100002);

                break;
            case 3://音频mp3
                $model = M('mp3');
                $workInfo = $model->find($id);
                break;
            case 4://音频直播
                $model = M('audio');
                $workInfo = $model->find($id);
                break;
            case 5://报告
                $model = M('report');
                $workInfo = $model->find($id);
                break;
            case 6://图片
                $model = M('picture');
                $workInfo = $model->find($id);
                break;
            case 7://会议
                $model = M('meeting');
                $workInfo = $model->find($id);
                break;
            case 8://问答
                $model = M('question');
                $workInfo = $model->find($id);
                break;
            case 9://问卷
                $model = M('question');
                $workInfo = $model->find($id);
                break;
            default:
                return false;
        }

        if (empty($workInfo)) return showErrorMsg(L('_DATA_NOT_EXIT_'),100002);
        if($workInfo['uid']==$this->userInfo->id || $workInfo['auth']==0){//本人 or 0
            return true;
        }elseif ($workInfo['auth'] == 1){//粉丝
            $follow_map['uid'] = $this->userInfo->id;
            $follow_map['puid'] = $workInfo['uid'];
            $is_floow = M('user_follow')->where($follow_map)->find();
            return empty($is_floow)?showErrorMsg('你还没有关注该用户，只有成为粉丝才可以操作！',100002):true;
        }elseif ($workInfo['auth']==2){//会员 or 付费
            $order_map1['uid'] = $this->userInfo->id;
            $order_map1['work_id'] = $id;
            $order_map1['status'] = 1;
            $order_map1['type'] = 12;
            $order_map1['deadline'] = array('gt',time());
            $is_vip = M('order')->where($order_map1)->find();

            $order_map2['uid'] = $this->userInfo->id;
            $order_map2['work_id'] = $id;
            $order_map2['status'] = 1;
            $order_map2['type'] = array('neq',12);
            $is_pay = M('order')->where($order_map2)->find();
            if (empty($is_pay)&&empty($is_vip)){
                return showErrorMsg('你必须先购买会员或支付才可以继续操作！',100002);
            }else{
                return true;
            }
        }elseif ($workInfo['auth']==3){//仅付费
            $order_map['uid'] = $this->userInfo->id;
            $order_map['work_id'] = $id;
            $order_map['status'] = 1;
            $order_map2['type'] = array('neq',12);
            $is_pay = M('order')->where($order_map)->find();
            return empty($is_pay)?showErrorMsg('你必须先购买才可以继续操作！',100002):true;
        }elseif ($workInfo['auth']==4){//密码
            return $workInfo['pwd']==$param['pwd']?true:showErrorMsg('你输入的密码有误',100002);
        }elseif ($workInfo['auth']==5){//F码
            $is_reservation = M('direct_reservation')->where(['uid'=>$this->userInfo->id,'direct_id'=>$id])->find();
            if (empty($is_reservation)) return showErrorMsg('你还没有预约本次活动',100002);
            return $is_reservation['F']==$param['f']?true:showErrorMsg('F码输入有误',100002);
        }

    }

    /**
     * @desc 权限
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @param $type 1 video，2 direct，3 mp3，4 audio，5 report ，6 picture，7 meeting，8 qa,9 question
     * @return array|bool
     */
    private function _auth_($param,$type)
    {
        if (empty($this->userInfo)) return showErrorMsg(L('_TOKEN_USELESS_'),100004);

        $id = $param['id'];
        switch ($type){
            case 1://视频
                $model = M('video');
                $workInfo = $model->find($id);
                break;
            case 2://直播
                $model = M('direct');
                $workInfo = $model->find($id);
                break;
            case 3://音频mp3
                $model = M('mp3');
                $workInfo = $model->find($id);
                break;
            case 4://音频直播
                $model = M('audio');
                $workInfo = $model->find($id);
                break;
            case 5://报告
                $model = M('report');
                $workInfo = $model->find($id);
                break;
            case 6://图片
                $model = M('picture');
                $workInfo = $model->find($id);
                break;
            case 7://会议
                $model = M('meeting');
                $workInfo = $model->find($id);
                break;
            case 8://问答
                $model = M('qa');
                $workInfo = $model->find($id);
                break;
            case 9://问卷
                $model = M('question');
                $workInfo = $model->find($id);
                break;
            default:
                return false;
        }

        if (empty($workInfo)) return showErrorMsg(L('_DATA_NOT_EXIT_'),100002);
        if($workInfo['uid']!==$this->userInfo->id ) return showErrorMsg('没有访问权限',100002);
        return true;
    }


    /**
     * @desc 问卷类型
     * @author Earl<guo@seosite.cn>
     * @param $k
     * @return mixed
     */
    private function _question_type_($k)
    {
        $list[1] = '视频';
        $list[2] = '音频';
        $list[3] = '会议';
        $list[4] = '问卷';
        return $list[$k];
    }

    /**
     * @desc 搜索待定
     * @author Earl <guo@seosite.cn> .
     * @updateTime
     * @param $param $type 1.打飞机实时，2.打飞机预约，3.飞行体验实时，4.飞行体验预约
     * @return array
     */
    public function search($param)
    {
        if (empty($this->userInfo)) return showErrorMsg(L('_TOKEN_USELESS_'),100004);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        return showErrorMsg('没有满足条件的时间',100002);
    }

    /**
     * @desc 添加推荐
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function addRecommend($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id,type');

        unset($check);

        $model = M('recommend');
        $map['type']    = $param['type'];
        $map['work_id'] = $param['id'];
        $info = $model->where($map)->find();

        if (!$info){

            $add_data = array(
                'work_id'   =>  $param['id'],
                'type'      =>  $param['type'],
                'uid'       =>  $this->userInfo->id,
                'create_time'   =>  time(),

            );

            $operation = $model->add($add_data);
            if ($operation) return showErrorMsg(L('_OPERATION_SUCCESS_'));
            return showErrorMsg(L('_OPERATION_FAIL_'),100002);
        }else{
            return showErrorMsg("已经被推荐过啦!",100002);
        }
    }

    /**
     * @desc 添加关注
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function addConnect($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id,type');

        unset($check);

        $model = M('connect');
        $map['type']    = $param['type'];
        $map['work_id'] = $param['id'];
        $info = $model->where($map)->find();

        if (!$info){
            $add_data = array(
                'work_id'   =>  $param['id'],
                'type'   =>  $param['type'],
                'uid'   =>  $this->userInfo->id,
                'create_time'   =>  time(),

            );

            $operation = $model->add($add_data);
            if ($operation) return showErrorMsg(L('_OPERATION_SUCCESS_'));
            return showErrorMsg(L('_OPERATION_FAIL_'),100002);
        }else{
            return showErrorMsg('已经关注过啦！',100002);
        }
    }

    /**
     * @desc 添加收藏
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function addCollect($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id,type');

        unset($check);

        $model = M('collect');
        $map['type']    = $param['type'];
        $map['work_id'] = $param['id'];
        $info = $model->where($map)->find();
        if ($info){
            $add_data = array(
                'work_id'   =>  $param['id'],
                'type'   =>  $param['type'],
                'uid'   =>  $this->userInfo->id,
                'create_time'   =>  time(),

            );

            $operation = $model->add($add_data);
            if ($operation) return showErrorMsg(L('_OPERATION_SUCCESS_'));
            return showErrorMsg(L('_OPERATION_FAIL_'),100002);
        }else{
            return showErrorMsg('已经收藏过啦！',100002);
        }

    }

    /**
     * @desc 添加评论
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function addComment($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id,type,puid,content');

        unset($check);


        $model = M('comment');

        $add_data = array(
            'work_id'   =>  $param['id'],
            'type'      =>  $param['type'],
            'uid'       =>  $this->userInfo->id,
            'puid'      =>  empty($param['puid'])?0:$param['puid'],
            'content'   =>  $param['content'],
            'create_time'   =>  time(),

        );

        $operation = $model->add($add_data);
        if ($operation) return showErrorMsg(L('_OPERATION_SUCCESS_'));
        return showErrorMsg(L('_OPERATION_FAIL_'),100002);
    }

    /**
     * @desc 点赞
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function addCommentParise($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id');

        unset($check);

        $model = M('comment_parise');

        $comment_id = $param['id'];

        $add_data = array(
            'uid'           =>  $this->userInfo->id,
            'comment_id'    =>  $comment_id,
            'create_time'   =>  time(),

        );

        $operation = $model->add($add_data);

        if ($operation) {
            M('comment')->where(['id'=>$comment_id])->setInc('praise_count');
            return showErrorMsg(L('_OPERATION_SUCCESS_'));
        }else{
            return showErrorMsg(L('_OPERATION_FAIL_'),100002);
        }
    }

    /**
     * @desc 取消赞
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function removeCommentParise($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id');

        unset($check);


        $model = M('comment_parise');

        $comment_id = $param['id'];

        $map['comment_id'] = $comment_id;
        $map['uid'] = $this->userInfo->id;
        $is_exist = $model->where($map)->find();
        if ($is_exist){
            $operation = $model->where($map)->delete();

            if ($operation) {
                M('comment')->where(['id'=>$comment_id])->setDec('praise_count');
                return showErrorMsg(L('_OPERATION_SUCCESS_'));
            }else{
                return showErrorMsg(L('_OPERATION_FAIL_'),100002);
            }

        }else{
            return showErrorMsg(L('_OPERATION_SUCCESS_'));
        }
    }

    /**
     * @desc 视频首页
     * @author Earl<guo@seosite.cn>
     * @return array
     */
    public function videoIndex($param)
    {
        //广告图分类:1 首页A，2 首页B，3 视频，4 音频，5 报告，6 图片，7 快讯，8 数据 ，9 会议，10 专栏，11 问答 ，12 头像 ，13 二维码
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        unset($check);

        $p1 = empty($param['p1']) ?: $param['p1'];
        $listRows1 = empty($param['listRows1']) ? 20 : $param['listRows1'];

        $p2 = empty($param['p2']) ?: $param['p2'];
        $listRows2 = empty($param['listRows2']) ? 20 : $param['listRows2'];

        $p3 = empty($param['p3']) ?: $param['p3'];
        $listRows3 = empty($param['listRows3']) ? 20 : $param['listRows3'];


        //1.bannerList
        $bannerObj = M('banner');
        if (!empty($this->bo_id)){
            $bannerMap['uid'] = $this->bo_id;
        }

        $bannerMap['banner_type'] = 3;
        $bannerList = $bannerObj->where($bannerMap)->select();

        //2.preview
        $directObj = M('direct');
//        $direct_map['direct_status'] = 0;
        $direct_map['status']       = 1;
        $direct_map['is_show']      = 1;
        if (!empty($this->bo_id)){
            $direct_map['uid'] = $this->bo_id;
            $tag_map['uid'] = array('in','0,'.$this->bo_id);
            $tag_map['type'] = 2;
            $previewTagList = M('tag')->where($tag_map)->select();
        }else{
            $tag_map['uid'] = 0;
            $tag_map['type'] = 2;
            $previewTagList = M('tag')->where($tag_map)->select();
        }

        if (!empty($param['pre_tag_id'])){
            $work_id = M('work_tag')->field("group_concat(work_id) work_id")->where(['type'=>2,'tag_id'=>$param['pre_tag_id']])->find();
            if (!empty($work_id['work_id'])) $direct_map['id'] = array('in',$work_id['work_id']);
        }

//        $direct_map['start_time']   = array('elt',time());


        list($previewList,$prePage) = _listPage($directObj,$direct_map,$p1,'direct_status desc,start_time asc,create_time desc','id,headsmall,title,start_time,end_time,create_time,location,direct_status,auth,status',$listRows1);

        if(!empty($previewList)){
            foreach ($previewList as $k=>$v){
                $previewList[$k]['status_text'] = $this->statusToText($v['status']);
                $previewList[$k]['direct_status_text'] = $this->statusToText($v['direct_status']);
            }
        }

        //3.热播排行
        $videoObj = M('video');
        if (!empty($this->bo_id)){
            $video_map['uid'] = $this->bo_id;
            $hot_tag_map['uid'] = array('in','0,'.$this->bo_id);
            $hot_tag_map['type'] = 1;
            $hotTagList = M('tag')->where($tag_map)->select();
        }else{
            $video_map['uid'] = 0;
            $tag_map['type'] = 1;
            $hotTagList = M('tag')->where($tag_map)->select();
        }

        if (!empty($param['hot_tag_id'])){
            $work_id = M('work_tag')->field("group_concat(work_id) work_id")->where(['type'=>2,'tag_id'=>$param['hot_tag_id']])->find();
            if (!empty($work_id['work_id'])) $direct_map['id'] = array('in',$work_id['work_id']);
        }
        $video_map['is_show']   = 1;
        list($videoList,$videoPage) = _listPage($videoObj,$video_map,$p2,'views desc,create_time desc','id,headsmall,title,duration_time,views,create_time',$listRows2);

        //4.recommend
        $recommendObj = M('recommend');

        if (!empty($this->bo_id)){
            $recommend_map['uid'] = $this->bo_id;
            $recommend_tag_map['uid'] = array('in','0,'.$this->bo_id);
            $recommend_tag_map['type'] = 1;
            $recommendTagList = M('tag')->where($tag_map)->select();
        }else{
            $recommend_map['uid'] = 0;
            $recommend_tag_map['type'] = 1;
            $recommendTagList = M('tag')->where($tag_map)->select();
        }

        $recommend_map['uid'] = !empty($this->bo_id) ? $this->bo_id :0;

        $recommend_map['type']  = 1;
        if (!empty($param['recommend_tag_id'])){
            $work_id = M('work_tag')->field("group_concat(work_id) work_id")->where(['type'=>2,'tag_id'=>$param['recommend_tag_id']])->find();
            if (!empty($work_id['work_id'])) $direct_map['id'] = array('in',$work_id['work_id']);
        }
        list($recommendList,$recommendPage) = _listPage($recommendObj,$recommend_map,$p3,'create_time desc','id,uid,work_id,create_time',$listRows3);

        if (!empty($recommendList)){
            foreach ($recommendList as $recommendK=>$recommendV){
                $info = M('video')->where(['id'=>$recommendV['work_id']])->find();
                if (empty($info)){
                    unset($recommendList[$recommendK]);
                }else{
                    $recommendList[$recommendK]['headsmall']    = $info['headsmall'];
                    $recommendList[$recommendK]['title']        = $info['title'];
                    $recommendList[$recommendK]['duration_time'] = $info['duration_time'];
                    $recommendList[$recommendK]['create_time']  = $info['create_time'];
                    $recommendList[$recommendK]['views']        = $info['views'];
                }
            }
        }
        $recommendList = array_merge($recommendList);


        $retData = array(
            'banner'        =>  $bannerList,
            'preview'       =>  $previewList,
            'hot'           =>  $videoList,
            'recommend'     =>  $recommendList,
            'pre_tag_list'  =>  $previewTagList,
            'hot_tag_list'  =>  $hotTagList,
            'recommend_tag_list'    =>  $recommendTagList
        );

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$retData);
    }

    /**
     * @desc 直播预告详情
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function directPreDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id,ImToken');

        unset($check);

        $model = M('direct');
        $info = $model->find($param['id']);

        //1 video，2 direct，3 mp3，4 audio，5 report ，6 picture，7 meeting，8 qa,9 question
        $this->_auth_($param,2);

        $model->where(['id'=>$param['id']])->setInc('views');

        $info['direct_auth'] = $this->direct_auth($info['auth']);

        $info['status_text'] = $this->statusToText($info['status']);
        $info['direct_status_text'] = $this->directStatusToText($info['status']);

        $info['direct_meeting_type'] = $this->direct_meeting_type($info['meeting_type']);

        $info['meeting_sponsor'] = !empty($info['meeting_sponsor'])?unserialize($info['meeting_sponsor'])==false?array():unserialize($info['meeting_sponsor']):array();

        $info['meeting_co_sponsor'] = !empty($info['meeting_co_sponsor'])?unserialize($info['meeting_co_sponsor'])==false?array():unserialize($info['meeting_co_sponsor']):array();

        $info['meeting_contractor'] = !empty($info['meeting_contractor'])?unserialize($info['meeting_contractor'])==false?array():unserialize($info['meeting_contractor']):array();

        $info['meeting_support'] = !empty($info['meeting_support'])?unserialize($info['meeting_support'])==false?array():unserialize($info['meeting_support']):array();

        $info['meeting_compere'] = !empty($info['meeting_compere'])?unserialize($info['meeting_compere'])==false?array():unserialize($info['meeting_compere']):array();

        $info['meeting_guest'] = !empty($info['meeting_guest'])?unserialize($info['meeting_guest'])==false?array():unserialize($info['meeting_guest']):array();

        $info['meeting_yc_guest'] = !empty($info['meeting_yc_guest'])?unserialize($info['meeting_yc_guest'])==false?array():unserialize($info['meeting_yc_guest']):array();

        $questionList = M('direct_question')->where(['direct_id'=>$info['id']])->select();

        if (!empty($questionList)){
            foreach ($questionList as&$v){
                $v['select'] = unserialize($v['select']) == false?array():unserialize($v['select']);
            }
        }
        $info['question'] = $questionList;

        //评价列表

        $tree = new Tree();
        $comment_map['work_id'] = $info['id'];
        $comment_map['type'] = 2;
        $commentList = M('comment')->field(null)->where($comment_map)->select();
        $info['comment_list'] = $tree->list2tree($commentList,'id','puid','_child','0','**');
        $info['comment_count'] = count($commentList);
        //预约个数
        $reservation = M('direct_reservation')->where(['direct_id'=>$info['id']])->count();
        $info['direct_reservation'] = $reservation;

        //是否关注
        $is_exist = M('connect')->where(['type'=>2,'work_id'=>$info['id']])->find();
        $info['is_connect'] = empty($is_exist)?0:1;

        //是否收藏
        $is_exist = M('collect')->where(['type'=>2,'work_id'=>$info['id']])->find();
        $info['is_collect'] = empty($is_exist)?0:1;

        //是否推荐
        $is_exist = M('recommend')->where(['type'=>2,'work_id'=>$info['id']])->find();
        $info['is_recommend'] = empty($is_exist)?0:1;

        //问答列表
        $qa_list = M('qa')->where(['type'=>2,'work_id'=>$info['id']])->select();
        $info['qa_list'] = $qa_list;
        $info['qa_count'] = count($qa_list);


        //gid
        $gid = M('im_group')->where(['type'=>1,'room_id'=>$info['room_id']])->getField('gid');

        $info['gid'] = empty($gid)?0:(int)$gid;

        //加入群聊
        $ImObj = new ImController();
        $joinInfo = $ImObj->addGroup($param['ImToken'],$gid);

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$info);
    }

    /**
     * @desc 视频详情|推荐详情
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function videoDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id');

        unset($check);

        $model = M('video');
        $info = $model->find($param['id']);

        //评价列表
        $comment_map['work_id'] = $info['id'];
        $comment_map['type'] = 1;
        $commentList = M('comment')->where($comment_map)->select();
        $tree = new Tree();
        $info['comment_list'] = $tree->list2tree($commentList,'id','puid','_child','0','**');
        $info['comment_count'] = count($commentList);

        //是否关注
        $is_exist = M('connect')->where(['type'=>1,'work_id'=>$info['id']])->find();
        $info['is_connect'] = empty($is_exist)?0:1;

        //是否收藏
        $is_exist = M('collect')->where(['type'=>1,'work_id'=>$info['id']])->find();
        $info['is_collect'] = empty($is_exist)?0:1;

        //是否推荐
        $is_exist = M('recommend')->where(['type'=>1,'work_id'=>$info['id']])->find();
        $info['is_recommend'] = empty($is_exist)?0:1;

        //问答列表
        $qa_list = M('qa')->where(['type'=>1,'work_id'=>$info['id']])->select();
        $info['qa_list'] = $qa_list;
        $info['qa_count'] = count($qa_list);

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$info);
    }

    /**
     * @desc 语音首页
     * @author Earl<guo@seosite.cn>
     * @return array
     */
    public function audioIndex($param)
    {
        //广告图分类:1 首页A，2 首页B，3 视频，4 音频，5 报告，6 图片，7 快讯，8 数据 ，9 会议，10 专栏，11 问答 ，12 头像 ，13 二维码
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        unset($check);


        $p1 = empty($param['p1']) ?: $param['p1'];
        $listRows1 = empty($param['listRows1']) ? 20 : $param['listRows1'];

        $p2 = empty($param['p2']) ?: $param['p2'];
        $listRows2 = empty($param['listRows2']) ? 20 : $param['listRows2'];

        $p3 = empty($param['p3']) ?: $param['p3'];
        $listRows3 = empty($param['listRows3']) ? 20 : $param['listRows3'];


        //1.bannerList
        $bannerObj = M('banner');
        $bannerMap['uid'] = $this->userInfo->id;
        $bannerMap['banner_type'] = 4;
        $bannerList = $bannerObj->where($bannerMap)->select();

        //2.preview
        $audioObj = M('audio');
        $audio_map['direct_status'] = 0;
        $audio_map['status']       = 1;
        $audio_map['is_show']      = 1;
        $audio_map['uid']          = $this->userInfo->id;
        $audio_map['start_time']   = array('elt',time());
        list($previewList,$prePage) = _listPage($audioObj,$audio_map,$p1,'start_time asc','id,headsmall,title,start_time,end_time,create_time,location,direct_status,auth',$listRows1);

        //3.mp3
        $mp3Obj = M('mp3');
        $mp3_map['uid']       = $this->userInfo->id;
        $mp3_map['is_show']   = 1;
        list($mp3List,$videoPage) = _listPage($mp3Obj,$mp3_map,$p2,'create_time desc','id,headsmall,title,duration_time,views,create_time',$listRows2);

        //4.recommend
        $recommendObj = M('mp3');
        $recommend_map['uid']   = $this->userInfo->id;
        $recommend_map['type']  = 1;
        list($recommendList,$recommendPage) = _listPage($recommendObj,$recommend_map,$p3,'create_time desc','id,uid,create_time',$listRows3);

        if (!empty($recommendList)){
            foreach ($recommendList as &$recommendV){
                $info = M('video')->where(['id'=>$recommendV['work_id']])->find();
                $recommendV['headsmall']    = $info['headsmall'];
                $recommendV['title']        = $info['title'];
                $recommendV['duration_time'] = $info['duration_time'];
                $recommendV['create_time']  = $info['create_time'];
                $recommendV['views']        = $info['views'];
            }
        }

        $retData = array(
            'banner'        =>  $bannerList,
            'preview'       =>  $previewList,
            'mp3'         =>  $mp3List,
            'recommend'     =>  $recommendList,
        );

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$retData);
    }


    /**
     * @desc 直播预告详情
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function audioPreDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id');

        unset($check);


        $model = M('audio');
        $info = $model->find($param['id']);

        //1 video，2 direct，3 mp3，4 audio，5 report ，6 picture，7 meeting，8 qa,9 question
        $this->_auth_($param,2);

        $model->where(['id'=>$param['id']])->setInc('views');

        $info['direct_auth'] = $this->direct_auth($info['auth']);

        $info['direct_status'] = $this->direct_status($info['status']);

        $info['direct_meeting_type'] = $this->direct_meeting_type($info['meeting_type']);

        $info['meeting_sponsor'] = !empty($info['meeting_sponsor'])?unserialize($info['meeting_sponsor'])==false?array():unserialize($info['meeting_sponsor']):array();

        $info['meeting_co_sponsor'] = !empty($info['meeting_co_sponsor'])?unserialize($info['meeting_co_sponsor'])==false?array():unserialize($info['meeting_co_sponsor']):array();

        $info['meeting_contractor'] = !empty($info['meeting_contractor'])?unserialize($info['meeting_contractor'])==false?array():unserialize($info['meeting_contractor']):array();

        $info['meeting_support'] = !empty($info['meeting_support'])?unserialize($info['meeting_support'])==false?array():unserialize($info['meeting_support']):array();

        $info['meeting_compere'] = !empty($info['meeting_compere'])?unserialize($info['meeting_compere'])==false?array():unserialize($info['meeting_compere']):array();

        $info['meeting_guest'] = !empty($info['meeting_guest'])?unserialize($info['meeting_guest'])==false?array():unserialize($info['meeting_guest']):array();

        $info['meeting_yc_guest'] = !empty($info['meeting_yc_guest'])?unserialize($info['meeting_yc_guest'])==false?array():unserialize($info['meeting_yc_guest']):array();

        $questionList = M('audio_question')->where(['direct_id'=>$info['id']])->select();

        if (!empty($questionList)){
            foreach ($questionList as&$v){
                $v['select'] = unserialize($v['select']) == false?array():unserialize($v['select']);
            }
        }
        $info['question'] = empty($questionList)?array():$questionList;

        //评价列表
        $tree = new Tree();
        $comment_map['work_id'] = $info['id'];
        $comment_map['type'] = 3;
        $commentList = M('comment')->field(null)->where($comment_map)->select();
        $info['comment_list'] = $tree->list2tree($commentList,'id','puid','_child','0','**');
        $info['comment_count'] = count($commentList);
        //预约个数
        $reservation = M('direct_reservation')->where(['direct_id'=>$info['id']])->count();
        $info['direct_reservation'] = $reservation;

        //是否关注
        $is_exist = M('connect')->where(['type'=>3,'work_id'=>$info['id']])->find();
        $info['is_connect'] = empty($is_exist)?0:1;

        //是否收藏
        $is_exist = M('collect')->where(['type'=>3,'work_id'=>$info['id']])->find();
        $info['is_collect'] = empty($is_exist)?0:1;

        //是否推荐
        $is_exist = M('recommend')->where(['type'=>3,'work_id'=>$info['id']])->find();
        $info['is_recommend'] = empty($is_exist)?0:1;

        //问答列表
        $qa_list = M('qa')->where(['type'=>3,'work_id'=>$info['id']])->select();
        $info['qa_list'] = $qa_list;
        $info['qa_count'] = count($qa_list);

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$info);
    }

    /**
     * @desc 视频详情|推荐详情
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function mp3Detail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id');

        unset($check);


        $model = M('mp3');
        $info = $model->find($param['id']);

        //评价列表
        $comment_map['work_id'] = $info['id'];
        $comment_map['type'] = 4;
        $commentList = M('comment')->where($comment_map)->select();
        $tree = new Tree();
        $info['comment_list'] = $tree->list2tree($commentList,'id','puid','_child','0','**');
        $info['comment_count'] = count($commentList);

        //是否关注
        $is_exist = M('connect')->where(['type'=>4,'work_id'=>$info['id']])->find();
        $info['is_connect'] = empty($is_exist)?0:1;

        //是否收藏
        $is_exist = M('collect')->where(['type'=>4,'work_id'=>$info['id']])->find();
        $info['is_collect'] = empty($is_exist)?0:1;

        //是否推荐
        $is_exist = M('recommend')->where(['type'=>4,'work_id'=>$info['id']])->find();
        $info['is_recommend'] = empty($is_exist)?0:1;

        //问答列表
        $qa_list = M('qa')->where(['type'=>4,'work_id'=>$info['id']])->select();
        $info['qa_list'] = $qa_list;
        $info['qa_count'] = count($qa_list);

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$info);
    }

    /**
     * @desc 报告首页
     * @author Earl<guo@seosite.cn>
     * @return array
     */
    public function reportIndex($param)
    {
        //广告图分类:1 首页A，2 首页B，3 视频，4 音频，5 报告，6 图片，7 快讯，8 数据 ，9 会议，10 专栏，11 问答 ，12 头像 ，13 二维码
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('time_type,hot');

        unset($check);


        $p1 = empty($param['p1']) ?: $param['p1'];
        $listRows1 = empty($param['listRows1']) ? 20 : $param['listRows1'];

        $p2 = empty($param['p2']) ?: $param['p2'];
        $listRows2 = empty($param['listRows2']) ? 20 : $param['listRows2'];


        //1.bannerList
        $bannerObj = M('banner');
        $bannerMap['uid'] = $this->userInfo->id;
        $bannerMap['banner_type'] = 5;
        $bannerList = $bannerObj->where($bannerMap)->select();

        //2.news
        $audioObj = M('news');
        list($previewList,$prePage) = _listPage($audioObj,null,$p1,'create_time desc',null,$listRows1);

        //3.report
        $time_type = empty($param['time_type'])?'':$param['time_type'];//本周1，本月2，不选，不传

        $hot = empty($param['hot'])?'':$param['hot'];//按照热度 desc,asc

        if (!empty($time_type)){
            if ($time_type==1){
                $time = strtotime(date('Y-m-d 23:59:59',(time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)));
            }else{
                $time = strtotime(date('Y-m-d 23:59:59', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')));
            }
            $report_map['create_time'] = array('elt',$time);
            $order = 'create_time desc';
        }elseif (!empty($hot)){
            if ($hot == 'desc'){
                $order = 'views desc,create_time desc';
            }else{
                $order = 'views asc,create_time desc';
            }

        }

        $reportObj = M('report');
        $report_map['uid']       = $this->userInfo->id;
        $report_map['is_show']   = 1;
        list($reportList,$videoPage) = _listPage($reportObj,$report_map,$p2,$order,'id,headsmall,title,author,tag_id,views,create_time',$listRows2);

        $retData = array(
            'banner'        =>  $bannerList,
            'preview'       =>  $previewList,
            'report'        =>  $reportList,
        );

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$retData);
    }

    /**
     * @desc 报告详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function reportDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id');

        unset($check);

        $model = M('report');
        $info = $model->find($param['id']);

        //博主信息
        $info['u_info'] = M('User')->where(['id'=>$info['uid']])->find();

        //评价列表
        $comment_map['work_id'] = $info['id'];
        $comment_map['type'] = 5;
        $commentList = M('comment')->where($comment_map)->select();
        $tree = new Tree();
        $info['comment_list'] = $tree->list2tree($commentList,'id','puid','_child','0','**');
        $info['comment_count'] = count($commentList);

        //是否关注
        $is_exist = M('connect')->where(['type'=>5,'work_id'=>$info['id']])->find();
        $info['is_connect'] = empty($is_exist)?0:1;

        //是否收藏
        $is_exist = M('collect')->where(['type'=>5,'work_id'=>$info['id']])->find();
        $info['is_collect'] = empty($is_exist)?0:1;

        //是否推荐
        $is_exist = M('recommend')->where(['type'=>5,'work_id'=>$info['id']])->find();
        $info['is_recommend'] = empty($is_exist)?0:1;

        //问答列表
        $qa_list = M('qa')->where(['type'=>5,'work_id'=>$info['id']])->select();
        $info['qa_list'] = $qa_list;
        $info['qa_count'] = count($qa_list);



        $info['sponsor_arr'] = !empty($info['sponsor_arr'])?unserialize($info['sponsor_arr'])==false?array():unserialize($info['sponsor_arr']):array();

        $info['co_sponsor_arr'] = !empty($info['co_sponsor_arr'])?unserialize($info['co_sponsor_arr'])==false?array():unserialize($info['co_sponsor_arr']):array();

        $info['contractor_arr'] = !empty($info['contractor_arr'])?unserialize($info['contractor_arr'])==false?array():unserialize($info['contractor_arr']):array();

        $info['support_arr'] = !empty($info['support_arr'])?unserialize($info['support_arr'])==false?array():unserialize($info['support_arr']):array();

        $info['compere_arr'] = !empty($info['compere_arr'])?unserialize($info['compere_arr'])==false?array():unserialize($info['compere_arr']):array();

        $info['guest_arr'] = !empty($info['guest_arr'])?unserialize($info['guest_arr'])==false?array():unserialize($info['guest_arr']):array();

        $info['apply_count'] = M('meeting_apply')->where(['meeting_id'=>$info['id']])->count();

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$info);
    }

    /**
     * @desc 图片首页
     * @author Earl<guo@seosite.cn>
     * @return array
     */
    public function picIndex($param)
    {
        //广告图分类:1 首页A，2 首页B，3 视频，4 音频，5 报告，6 图片，7 快讯，8 数据 ，9 会议，10 专栏，11 问答 ，12 头像 ，13 二维码
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('time_type,hot');

        unset($check);

        $p1 = empty($param['p1']) ?: $param['p1'];
        $listRows1 = empty($param['listRows1']) ? 20 : $param['listRows1'];

        $p2 = empty($param['p2']) ?: $param['p2'];
        $listRows2 = empty($param['listRows2']) ? 20 : $param['listRows2'];


        //1.bannerList
        $bannerObj = M('banner');
        $bannerMap['uid'] = $this->userInfo->id;
        $bannerMap['banner_type'] = 6;
        $bannerList = $bannerObj->where($bannerMap)->select();

        //2.news
        $audioObj = M('news');
        list($previewList,$prePage) = _listPage($audioObj,null,$p1,'create_time desc',null,$listRows1);

        //3.picture
        $time_type = empty($param['time_type'])?'':$param['time_type'];//本周1，本月2，不选，不传

        $hot = empty($param['hot'])?'':$param['hot'];//按照热度 desc,asc

        if (!empty($time_type)){
            if ($time_type==1){
                $time = strtotime(date('Y-m-d 23:59:59',(time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)));
            }else{
                $time = strtotime(date('Y-m-d 23:59:59', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')));
            }
            $pic_map['create_time'] = array('elt',$time);
            $order = 'create_time desc';
        }elseif (!empty($hot)){
            if ($hot == 'desc'){
                $order = 'views desc,create_time desc';
            }else{
                $order = 'views asc,create_time desc';
            }

        }

        $pictureObj = M('picture');
        $pic_map['uid']       = $this->userInfo->id;
        $pic_map['is_show']   = 1;
        list($reportList,$videoPage) = _listPage($pictureObj,$pic_map,$p2,$order,'id,headsmall,title,author,tag_id,views,create_time',$listRows2);

        $retData = array(
            'banner'        =>  $bannerList,
            'preview'       =>  $previewList,
            'picture'        =>  $reportList,
        );

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$retData);
    }

    /**
     * @desc 图片详情
     * @author Earl<guo@seosite.cn>
     * @param $param
     * @return array
     */
    public function picDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id');

        unset($check);

        $model = M('picture');
        $info = $model->find($param['id']);

        //评价列表
        $comment_map['work_id'] = $info['id'];
        $comment_map['type'] = 6;
        $commentList = M('comment')->where($comment_map)->select();
        $tree = new Tree();
        $info['comment_list'] = $tree->list2tree($commentList,'id','puid','_child','0','**');
        $info['comment_count'] = count($commentList);

        //是否关注
        $is_exist = M('connect')->where(['type'=>6,'work_id'=>$info['id']])->find();
        $info['is_connect'] = empty($is_exist)?0:1;

        //是否收藏
        $is_exist = M('collect')->where(['type'=>6,'work_id'=>$info['id']])->find();
        $info['is_collect'] = empty($is_exist)?0:1;

        //是否推荐
        $is_exist = M('recommend')->where(['type'=>6,'work_id'=>$info['id']])->find();
        $info['is_recommend'] = empty($is_exist)?0:1;

        //问答列表
        $qa_list = M('qa')->where(['type'=>6,'work_id'=>$info['id']])->select();
        $info['qa_list'] = $qa_list;
        $info['qa_count'] = count($qa_list);

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$info);
    }

    /**
     * @desc 快讯首页
     * @author Earl<guo@seosite.cn>
     * @return array
     */
    public function newsIndex($param)
    {
        //广告图分类:1 首页A，2 首页B，3 视频，4 音频，5 报告，6 图片，7 快讯，8 数据 ，9 会议，10 专栏，11 问答 ，12 头像 ，13 二维码
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('tag_id');

        unset($check);

        $p1 = empty($param['p1']) ?: $param['p1'];
        $listRows1 = empty($param['listRows1']) ? 20 : $param['listRows1'];

        $p2 = empty($param['p2']) ?: $param['p2'];
        $listRows2 = empty($param['listRows2']) ? 20 : $param['listRows2'];


        //1.bannerList
        $bannerObj = M('banner');
        $bannerMap['uid'] = $this->userInfo->id;
        $bannerMap['banner_type'] = 7;
        $bannerList = $bannerObj->where($bannerMap)->select();

        //2.news
        $audioObj = M('news');
        $tag = empty($param['tag_id'])?'':$param['tag_id'];
        if (!empty($tag)){
            $map['tag_id'] = array('like',$tag.'%');
        }else{
            $map = null;
        }

        list($newsList,$prePage) = _listPage($audioObj,$map,$p1,'create_time desc',null,$listRows1);


        $retData = array(
            'banner'        =>  $bannerList,
            'new'           =>  $newsList,
        );

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$retData);
    }

    /**
     * @desc 专栏列表【弃用】
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function columnistList($param)
    {
        //广告图分类:1 首页A，2 首页B，3 视频，4 音频，5 报告，6 图片，7 快讯，8 数据 ，9 会议，10 专栏，11 问答 ，12 头像 ，13 二维码
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        unset($check);

        $p1 = empty($param['p1']) ?: $param['p1'];
        $listRows1 = empty($param['listRows1']) ? 20 : $param['listRows1'];

        //1.bannerList
        $bannerObj = M('banner');
//        $bannerMap['uid'] = $this->userInfo->id;
        $bannerMap['banner_type'] = 10;
        $bannerList = $bannerObj->where($bannerMap)->select();

        //2.columnist
        $columnistObj = M('columnist');
        list($columnistList,$columnistPage) = _listPage($columnistObj,null,$p1,'ontop ASC,num ASC,create_time DESC',null,$listRows1);

        if (!empty($columnistList)){
            foreach ($columnistList as &$v){
                $v['u_follow'] = M('user_follow')->where(['puid'=>$v['uid']])->count();
                $picture = M('picture')->where(['uid'=>$v['uid']])->count();
                $report = M('report')->where(['uid'=>$v['uid']])->count();
                $v['article'] = $picture+$report;
            }
        }

        $retData = array(
            'banner'        =>  $bannerList,
            'columnistList'          =>  $columnistList,
            'columnistPage'       =>  $columnistPage,
        );

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$retData);
    }

    /**
     * @desc 专栏详情【弃用】
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function columnistDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id');

        unset($check);

        $model = M('columnist');
        $info = $model->find($param['id']);

        $info['u_follow'] = M('user_follow')->where(['puid'=>$info['uid']])->count();

        $is_connect = M('user_follow')->where(['uid'=>$this->userInfo->id,'puid'=>$info['uid']])->find();
        $info['is_collect'] = empty($is_connect)?0:1;

        $picture = M('picture')->where(['uid'=>$info['uid']])->count();
        $report = M('report')->where(['uid'=>$info['uid']])->count();
        $info['article'] = $picture+$report;

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$info);
    }



    /**
     * @desc 会议首页
     * @author Earl<guo@seosite.cn>
     * @return array
     */
    public function meetingIndex($param)
    {
        //广告图分类:1 首页A，2 首页B，3 视频，4 音频，5 报告，6 图片，7 快讯，8 数据 ，9 会议，10 专栏，11 问答 ，12 头像 ，13 二维码
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        unset($check);

        $p1 = empty($param['p1']) ?: $param['p1'];
        $listRows1 = empty($param['listRows1']) ? 20 : $param['listRows1'];

        $p2 = empty($param['p2']) ?: $param['p2'];
        $listRows2 = empty($param['listRows2']) ? 20 : $param['listRows2'];


        //1.bannerList
        $bannerObj = M('banner');
        $bannerMap['uid'] = $this->userInfo->id;
        $bannerMap['banner_type'] = 9;
        $bannerList = $bannerObj->where($bannerMap)->select();

        //2.news
        $newsObj = M('news');
        list($newsList,$newsPage) = _listPage($newsObj,null,$p1,'create_time desc',null,$listRows1);

        //3.meeting
        $meetingObj = M('meeting');
        $meeting_map['uid']       = $this->userInfo->id;
        $meeting_map['is_show']   = 1;
        list($meetingList,$meetingPage) = _listPage($meetingObj,$meeting_map,$p2,'create_time desc','id,headsmall,title,start_time,location',$listRows2);

        if (!empty($meetingList)){
            foreach ($meetingList as &$v){
                $v['count'] = M('meeting_apply')->where(['meeting_id'=>$v['id']])->count();
            }
        }

        $retData = array(
            'banner'        =>  $bannerList,
            'news'          =>  $newsList,
            'meeting'       =>  $meetingList,
            'meetingPage'       =>  $meetingPage,
        );

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$retData);
    }

    /**
     * @desc 会议详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function meetingDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id');

        unset($check);

        $model = M('meeting');
        $info = $model->find($param['id']);

        //评价列表
        $comment_map['work_id'] = $info['id'];
        $comment_map['type'] = 9;
        $commentList = M('comment')->where($comment_map)->select();
        $tree = new Tree();
        $info['comment_list'] = $tree->list2tree($commentList,'id','puid','_child','0','**');
        $info['comment_count'] = count($commentList);

        //是否关注
        $is_exist = M('connect')->where(['type'=>9,'work_id'=>$info['id']])->find();
        $info['is_connect'] = empty($is_exist)?0:1;

        //是否收藏
        $is_exist = M('collect')->where(['type'=>9,'work_id'=>$info['id']])->find();
        $info['is_collect'] = empty($is_exist)?0:1;

        //是否推荐
        $is_exist = M('recommend')->where(['type'=>9,'work_id'=>$info['id']])->find();
        $info['is_recommend'] = empty($is_exist)?0:1;

        //问答列表
        $qa_list = M('qa')->where(['type'=>9,'work_id'=>$info['id']])->select();
        $info['qa_list'] = $qa_list;
        $info['qa_count'] = count($qa_list);

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$info);
    }

    /**
     * @desc 会议报名
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function applyMeeting($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('id,username,phone,company_name,job,is_invoice,invoice_type,invoice_c_name,invocie_c_id,invoice_c_address,invoice_c_phone,invoice_c_bank_name,invoice_c_bank_id');

        unset($check);

        $insert_data = array(
                'meeting_id'            =>  $param['id'],
                'uid'                   =>  $this->userInfo->id,
                'username'              =>  empty($param['username'])?'':$param['username'],
                'phone'                 =>  empty($param['phone'])?'':$param['phone'],
                'company_name'          =>  empty($param['company_name'])?'':$param['company_name'],
                'job'                   =>  empty($param['job'])?'':$param['job'],
                'is_invoice'            =>  empty($param['is_invoice'])?'':$param['is_invoice'],
                'invoice_type'          =>  empty($param['invoice_type'])?'':$param['invoice_type'],
                'invoice_c_name'        =>  empty($param['invoice_c_name'])?'':$param['invoice_c_name'],
                'invocie_c_id'          =>  empty($param['invocie_c_id'])?'':$param['invocie_c_id'],
                'invoice_c_address'     =>  empty($param['invoice_c_address'])?'':$param['invoice_c_address'],
                'invoice_c_phone'       =>  empty($param['invoice_c_phone'])?'':$param['invoice_c_phone'],
                'invoice_c_bank_name'   =>  empty($param['invoice_c_bank_name'])?'':$param['invoice_c_bank_name'],
                'invoice_c_bank_id'     =>  empty($param['invoice_c_bank_id'])?'':$param['invoice_c_bank_id'],
                'is_pay'                =>  $param['id'],
                'pay_type'              =>  '',
                'pay_time'              =>  '',
                'status'                =>  1,
                'create_time'           =>  time()
        );

        $operation = M('meeting_apply')->add($insert_data);
    }


    public function applyMeetingReward($param)
    {
        if (empty($this->userInfo)) return showErrorMsg(L('_TOKEN_USELESS_'),100004);

        $insert_data = array(
            'meeting_id'    =>  $param['id'],
            'uid'    =>  $this->userInfo->id,
            'username'    =>  empty($param['username'])?'':$param['username'],
            'phone'    =>  empty($param['phone'])?'':$param['phone'],
            'company_name'    =>  empty($param['company_name'])?'':$param['company_name'],
            'job'    =>  empty($param['job'])?'':$param['job'],
            'is_invoice'    =>  empty($param['is_invoice'])?'':$param['is_invoice'],
            'invoice_type'    =>  empty($param['invoice_type'])?'':$param['invoice_type'],
            'invoice_c_name'    =>  empty($param['invoice_c_name'])?'':$param['invoice_c_name'],
            'invocie_c_id'    =>  empty($param['invocie_c_id'])?'':$param['invocie_c_id'],
            'invoice_c_address'    =>  empty($param['invoice_c_address'])?'':$param['invoice_c_address'],
            'invoice_c_phone'    =>  empty($param['invoice_c_phone'])?'':$param['invoice_c_phone'],
            'invoice_c_bank_name'    =>  empty($param['invoice_c_bank_name'])?'':$param['invoice_c_bank_name'],
            'invoice_c_bank_id'    =>  empty($param['invoice_c_bank_id'])?'':$param['invoice_c_bank_id'],
            'is_pay'    =>  $param['id'],
            'pay_type'    =>  '',
            'pay_time'    =>  '',
            'status'    =>  1,
            'create_time'    =>  time()
        );

        $operation = M('meeting_apply')->add($insert_data);
    }

    /**
     * @desc 问卷首页
     * @author Earl<guo@seosite.cn>
     * @return array
     */
    public function qaIndex($param)
    {
        //广告图分类:1 首页A，2 首页B，3 视频，4 音频，5 报告，6 图片，7 快讯，8 数据 ，9 会议，10 专栏，11 问答 ，12 头像 ，13 二维码，14 问卷
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        unset($check);

        $p1 = empty($param['p1']) ?: $param['p1'];
        $listRows1 = empty($param['listRows1']) ? 20 : $param['listRows1'];

        $p2 = empty($param['p2']) ?: $param['p2'];
        $listRows2 = empty($param['listRows2']) ? 20 : $param['listRows2'];


        //1.bannerList
        $bannerObj = M('banner');
        $bannerMap['uid'] = $this->userInfo->id;
        $bannerMap['banner_type'] = 14;
        $bannerList = $bannerObj->where($bannerMap)->select();

        //2.question list
        $questionObj = M('question');
        $question_map['uid']      = $this->userInfo->id;
        $question_map['is_show']  = 1;
        list($quetionList,$newsPage) = _listPage($questionObj,$question_map,$p1,'create_time desc','id,type,title,deadline,create_time',$listRows1);


        if (!empty($quetionList)){
            foreach ($quetionList as &$v){
                $v['typeText'] = $this->_question_type_($v['type']);
            }
        }

        $retData = array(
            'banner'        =>  $bannerList,
            'questionList'          =>  $quetionList,
        );

        return showErrorMsg(L("_OPERATION_SUCCESS_"),0,2,$retData);
    }
}